package com.summer.hundred;

public class que4 {
    public static void main(String[] args) {
       int[] nums1 ={1};
       int[] nums2 = {1};
        System.out.println(findMedianSortedArrays(nums1,nums2));
    }
    public static double findMedianSortedArrays(int[] nums1, int[] nums2) {
        int n1L = nums1.length;
        int n2L = nums2.length;
        int n1 = 0;
        int n2 = 0;
        double middle=0;
        int[] num3 = new int[n1L+n2L];
        int i = 0;
        for (i=0;i<num3.length;i++){
            if(n1>=n1L||n2>=n2L) break;
            num3[i] = nums1[n1]>nums2[n2]?nums2[n2++]:nums1[n1++];
        }
        if (n1L==0){
            for (int i1 = 0; i1 < num3.length; i1++) {
                num3[i1] = nums2[i1];
            }
        }
        if (n2L==0){
            for (int i1 = 0; i1 < num3.length; i1++) {
                num3[i1] = nums1[i1];
            }
        }
        if(n1>=n1L&&i<=num3.length-1){
            for(int k = i;k <num3.length;k++,i++){
                num3[k] = nums2[n2++];
            }

        }
        if(n2>=n2L&&i<=num3.length-1){
            for(int k = i;k <num3.length;k++,i++){
                num3[k] = nums1[n1++];
            }
        }
        if ((n1L+n2L)%2!=0&&(n1L+n2L)!=0){
            if ((n1L+n2L)==1){
                middle =num3[0];
            }else {
                middle = num3[(n1L+n2L-1)/2];
            }
        }else if((n1L+n2L)%2==0&&(n1L+n2L)!=0){
            middle = (num3[(n1L+n2L)/2-1]+num3[(n1L+n2L)/2])/2.0;
        }

       return middle;

    }
}
